const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: './',
  indexPath: 'index.html',
  outputDir: 'dist',
  assetsDir: 'web',
  productionSourceMap: false,

  devServer: {
    port: 1007,
    proxy: {
      '/data': {
        target: 'http://47.95.171.8:8787/',
        pathRewrite: {
          '^/data': '/' //重写接口
        },
        ws: true, //是否代理websockets
        changeOrigin: true // 设置同源  默认false，是否需要改变原始主机头为目标URL
      }
    }
  },
  lintOnSave: true,
  chainWebpack: config => {
    config.plugins.delete('prefetch')
    config.plugins.delete('preload')
    config.resolve.alias.set('@', path.join(__dirname, 'src')).set('img', resolve('src/assets'))
  },

  // css: {
  //   loaderOptions: {
  //     less: {
  //       //import: path.resolve(__dirname, '@/styles/common.less')
  //     }
  //   }
  // }
  configureWebpack: {
    resolve: {
      alias: {}
    },
    optimization: {
      runtimeChunk: {
        name: entrypoint => `runtime~${entrypoint.name}`
      },
      splitChunks: {
        minChunks: 2,
        minSize: 20000,
        maxAsyncRequests: 20,
        maxInitialRequests: 30,
        name: false
      }
    },
    externals: {
      AMap: 'AMap'
    }
  },
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [path.resolve(__dirname, './src/styles/common.less')]
    }
  }
}
